﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNAGlobe
{
    public class FPSCounter
    {
        public int frameRate = 0;
        int frameCounter = 0;
        TimeSpan elapsedTime = TimeSpan.Zero;

        public void Update(GameTime gameTime)
        {
            elapsedTime += gameTime.ElapsedGameTime;

            if (elapsedTime > TimeSpan.FromSeconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                frameRate = frameCounter;
                frameCounter = 0;
            }
        }

        public void Draw(
            SpriteBatch spriteBatch, SpriteFont spriteFont,
            GameTime gameTime)
        {
            frameCounter++;
            string fps = string.Format("FPS: {0}", frameRate);
            spriteBatch.DrawString(spriteFont, fps, new Vector2(32, 32), Color.White);
        }
    }

    public static class Utils
    {
        public static FPSCounter FrameCounter = new FPSCounter();
    }
}
